//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbLoaiHinhHD
    {
        public static DataTable Search(ETbLoaiHinhHD bl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaLHHD", bl.MaLHHD);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbLoaiHinhHD_Search", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu_Sua(ETbLoaiHinhHD bl)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaLHHD", bl.MaLHHD);
            pr[1] = new SqlParameter(@"TenLHHD", bl.TenLHHD);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbLoaiHinhHD_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu(ETbLoaiHinhHD bl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaLHHD", bl.MaLHHD);
        
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbLoaiHinhHD_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbLoaiHinhHD_SelectAll", null);
            return all;
        }
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbLoaiHinhHD_SelectAll1", null);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbLoaiHinhHD OTbLoaiHinhHD)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[1] = new SqlParameter(@"TenLHHD", OTbLoaiHinhHD.TenLHHD);
            pr[2] = new SqlParameter(@"MoTa", OTbLoaiHinhHD.MoTa);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbLoaiHinhHD_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbLoaiHinhHD OTbLoaiHinhHD)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaLHHD", OTbLoaiHinhHD.MaLHHD);
            pr[1] = new SqlParameter(@"TenLHHD", OTbLoaiHinhHD.TenLHHD);
            pr[2] = new SqlParameter(@"MoTa", OTbLoaiHinhHD.MoTa);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbLoaiHinhHD_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaLHHD)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaLHHD",MaLHHD);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbLoaiHinhHD_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbLoaiHinhHD SelectByID(int MaLHHD)
        {
            ETbLoaiHinhHD OTbLoaiHinhHD = new ETbLoaiHinhHD();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaLHHD",MaLHHD);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbLoaiHinhHD_SelectByID", pr);
            if (idr.Read())
              OTbLoaiHinhHD = GetOneTbLoaiHinhHD(idr);
            idr.Close();
            idr.Dispose();
            return OTbLoaiHinhHD;
        }
//-----------------------------------------------------------//
        private static ETbLoaiHinhHD GetOneTbLoaiHinhHD(IDataReader idr)
       {
            ETbLoaiHinhHD OTbLoaiHinhHD = new ETbLoaiHinhHD();
                if (idr["MaLHHD"] != DBNull.Value)
                    OTbLoaiHinhHD.MaLHHD = (int)idr["MaLHHD"];
                if (idr["TenLHHD"] != DBNull.Value)
                    OTbLoaiHinhHD.TenLHHD = (string)idr["TenLHHD"];
                if (idr["MoTa"] != DBNull.Value)
                    OTbLoaiHinhHD.MoTa = (string)idr["MoTa"];
            return OTbLoaiHinhHD;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaLHHD)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaLHHD",MaLHHD);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbLoaiHinhHD_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbLoaiHinhHD> ListAll()
        {
            List<ETbLoaiHinhHD> list = new List<ETbLoaiHinhHD>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbLoaiHinhHD_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbLoaiHinhHD(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}
